

cd "/Users/gaborsimonovits/Dropbox/populism/jop/final_replication_material"
*** Read in raw data


use raw_data_lucid.dta
*
** Demographics


* Inpute state based on zip code

gen zipcode=real(zip)
drop zip
merge m:m zipcode using  zip_to_state.dta
drop if _m==2
drop _m

decode state, gen (statee)
drop state
rename statee state
replace state=state_name if state==""



*** Recode demographic variables

* Education

replace education="" if education== "-3105" 

destring education, replace
recode educ (1=1) (2=2) (3 4 5 = 3) (6=4) (7 8 =5), gen (educ)
drop education
label val educ edu



destring age, gen(exact_age)
drop age
egen age=cut(exact_age), at(18, 40, 60, 200)  icodes
label define age 0 "18_40" 1 "40_60" 2 "60_plus" 
label values age age

* Gender


destring gender, replace

label define gender 1 "male" 2 "female" 
label values gender gender



* Race

destring eth, gen(race)
replace race=3 if race>2

label define race 1 "white" 2 "black" 3 "other" 
label values race race


* Hispanic


destring hisp, replace
recode hispanic  (1 16 =0)  (2 3 4 5 6 7 8 9 10 11 12 13 14 15 =1)

label define hisp 0 "no" 1 "yes" 
label values hisp hisp


* Income


replace hhi="" if hhi== "-3105" | hhi=="1917" | hhi=="more" 
destring hhi, replace

recode hhi  (1 2  3=1) (4 5 6 7 8 =2) (9 10 11 12 13 14 15 16 17 18=3) (19 20 21 22 23 24 = 4), gen (income)

label define inc 1 "25_less" 2 "25_50" 3 "50_100" 4 "100_plus" 
label values inc inc 


*** Pre-treatment variables

egen pid_intensity=rowmean(pintens_1 pintens_2 pintens_3 pintens_4)
replace pid_intensity= pid_intensity/0.04


tab respo,g (r)
renvars r1 r2 / democrat republican

gen white=race==1
gen female=gend==2
gen college=(educ>3)
gen pid3=.
replace pid3=1 if pid1==2 | pidi==2
replace pid3=-1 if pid1==1 | pidi==1
replace pid3=0 if  pidi==3 | pidi==4
tab pid3, g(pi)
renvars pi1 pi2 pi3 / republican_party independent democrat_party

*** Treatment conditions

replace erosion_condition="control" if erosion_condition==""

tab erosion_condition, g (ee)
tab threat_prime, g (tt)

renvars ee1 ee2 ee3  tt2 / inparty  control outparty threatened

gen  inparty_threatened= inparty*threatened 

gen inparty_republican=inparty*republican

** drop observations with no outcome measure

egen temp=rownonmiss(COURT BANPROTS PROSJOUR DISQCRIT OBEYCOUR COURT_c BANPROTS_c PROSJOUR_c DISQCRIT_c OBEYCOUR_c)
drop if temp==0

** drop observations from duplicate respondents

 duplicates tag rid, g (dup)
keep if dup==0
drop dup


** define outcome measures for

** experimental groups 

egen erosion=rowmean(COURT BANPROTS PROSJOUR DISQCRIT OBEYCOUR)

** control groups 

egen erosion_c=rowmean(COURT_c BANPROTS_c PROSJOUR_c DISQCRIT_c OBEYCOUR_c)

** govwernor related items only

egen erosion_c_gov=rowmean( BANPROTS_c PROSJOUR_c  )


replace erosion=erosion*100
replace erosion_c=erosion_c*100
replace erosion_c_gov=100*erosion_c_gov



*** Add the party of state governors

** Governors

merge m:m state using governors.dta
drop if _m==2
tab gov, g (gov)
renvars gov1 gov2 / demgov repgov
gen gov_cong= gov== respondent_party



save "/Users/gaborsimonovits/Dropbox/populism/jop/final_replication_material/erosion.dta", replace
